package fcrpt

class RpmRtmController {
    def dynamicQueryService
    def rpmRtm(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList=[]
        def rpmRtm=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'rpmRtm'
            rpmRtm = dynamicQueryService.queryForList(params)
            if (rpmRtm.size() > 0) {
                tableHeadList = rpmRtm[0].keySet()
            }
            params.SYS_QUERY_NAME = 'rpmRtmCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
        }

        [startno:params.startno?:'',
         endno:params.endno?:'',
         pageSize:pageSize,
         totalCount: totalCount,
         pageSizeList: pageSizeList,
         tableHeadList:tableHeadList,
         rpmRtm:rpmRtm,
         startTime                 : params.startTime ?: '',
         endTime                   : params.endTime ?: '',
         lotId:params.lotId?:'',
         parentId:params.parentId?:'',
         partName:params.partName?:'',
         tuhao:params.tuhao?:''
        ]
    }

    def rpmRtmTwo(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList=[]
        def rpmRtmTwo=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0

            params.SYS_QUERY_NAME = 'rpmRtmTwo'
            rpmRtmTwo = dynamicQueryService.queryForList(params)
            if (rpmRtmTwo.size() > 0) {
                tableHeadList = rpmRtmTwo[0].keySet()
            }

        print(params.lotId)
        print(params.step)
        [startno:params.startno?:'',
         endno:params.endno?:'',
         pageSize:pageSize,
         totalCount: totalCount,
         pageSizeList: pageSizeList,
         tableHeadList:tableHeadList,
         rpmRtmTwo:rpmRtmTwo,
         lotId:params.lotId?:'',
         step:params.step?:''
        ]
    }

    def exportExcel() {
        def sysQueryName


        sysQueryName = params.SYS_QUERY_NAME

        params.startno = 1
        params.endno = 99999999999999999
        params.SYS_QUERY_NAME = sysQueryName
        def dataList = dynamicQueryService.queryForList(params)
        def tableHeadList =  []
        if(dataList.size()>0){
            tableHeadList =  dataList[0].keySet()
        }
        String fileName = new String("${sysQueryName}.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${fileName};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}", model: [dataList: dataList,tableHeadList:tableHeadList,startno:params.startno?:'',endno:params.endno?:''])
    }
}
